﻿using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;
using DAL;
using BLL;
using System.IO;
using System.Data;
using System.Xml;
using System.Web.Security;
using System.Security.Cryptography;
using System.Net;
using System.Web;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;

namespace Web.Old_App_Code
{

    /// <summary>
    ///ViewStateCompression 的摘要说明
    /// </summary>
    public class ViewStateCompression
    {
        // Methods
        public static byte[] Compress(byte[] pBytes)
        {
            MemoryStream baseOutputStream = new MemoryStream();
            Deflater deflater = new Deflater(9);
            DeflaterOutputStream stream2 = new DeflaterOutputStream(baseOutputStream, deflater, 0x20000);
            stream2.Write(pBytes, 0, pBytes.Length);
            stream2.Close();
            return baseOutputStream.ToArray();
        }

        public static byte[] DeCompress(byte[] pBytes)
        {
            InflaterInputStream stream = new InflaterInputStream(new MemoryStream(pBytes));
            MemoryStream stream2 = new MemoryStream();
            byte[] buffer = new byte[0x1000];
            while (true)
            {
                int count = stream.Read(buffer, 0, buffer.Length);
                if (count > 0)
                {
                    stream2.Write(buffer, 0, count);
                }
                else
                {
                    stream.Close();
                    return stream2.ToArray();
                }
            }
        }

    }
}